using System;
using System.Collections.Generic;
using System.Text;
using QLPMT_DTO;
using QLPMT_DAO;

namespace QLPMT_BUS
{
   public class LogInBUS
    {
       //
       public void config(string host, string db_name, string db_user, string db_pass)
       {
           //new LogInDAO(host, db_name, db_user, db_pass).config(host, db_name, db_user, db_pass);
           new LogInDAO(host, db_name, db_user, db_pass).config(host, db_name, db_user, db_pass);
       }
       public LogIn GetLogIn(string user, string pass)
       {
           List<LogIn> list = new LogInDAO().GetAll();
           LogIn temp = new LogIn();
           foreach (LogIn X in list)
           {
               if (string.Compare(X.Pass, pass) == 0 && string.Compare(X.User, user) == 0)
               {
                   return X;
               }
           }
           return temp;
       }
       public List<LogIn> GetAll()
       {
           return new LogInDAO().GetAll();
       }
       // Kiem tra dang ki
       public Boolean IsLogIn(string user, string pass)
       {
           List<LogIn> list = new LogInDAO().GetAll();
           foreach (LogIn X in list)
           {
               if (string.Compare(X.Pass, pass) == 0 && string.Compare(X.User, user) == 0)
               {
                   return true;
               }
           }
           return false;
       }
       // Them 1 nguoi dung moi
       public Boolean Insert(string user, string pass, string passsecond)
       {
           Boolean flag = true;
           try
           {
               if (string.Compare(pass, passsecond) == 0)
               {
                   if (string.IsNullOrEmpty(user) == true)
                   {
                       flag = false;
                   }
                   else
                   {
                       LogIn dto = new LogIn(user, pass, "0");
                       new LogInDAO().Insert(dto);
                   }
               }
               else
               {
                   flag= false;
               }
           }
           catch
           {
               return false;
           }
           return flag;
       }
       public Boolean Update(string ten, string matkhau, string ma)
       {
           try
           {
               LogIn dto = new LogIn(ten, matkhau, ma);
               new LogInDAO().Update(dto);
           }
           catch
           {
               return false;
           }
           return true;
       }
       public void delete(string ten)
       {
           try
           {
               LogIn dto = new LogIn();
               dto.User = ten;
               new LogInDAO().delete(dto);
           }
           catch
           {


           }
       }
    }
}
